using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using DTO;

namespace DAL
{
   public class tbsanphamDAL
    {
        private SqlConnection cn = null;
        public tbsanphamDAL()
        {
            cn = new SqlConnection(ConfigurationManager.ConnectionStrings["strConnection"].ConnectionString);
            cn.Open();
        }
         public tbsanphamDAL(tbdanhmucDAL thach)
        {
            this.cn = new SqlConnection(ConfigurationManager.ConnectionStrings["strConnection"].ConnectionString);
            this.cn.Open();
        }
        public void Insert(tbsanpham sanpham)
        {
            SqlCommand cm = new SqlCommand("sanpham_Insert", cn);
            cm.CommandType = CommandType.StoredProcedure;
            cm.Parameters.AddWithValue("@masanpham", sanpham.Masanpham);
            cm.Parameters.AddWithValue("@madanhmuc", sanpham.Madanhmuc);
            cm.Parameters.AddWithValue("@madiadiem", sanpham.Madiadiem);
            cm.Parameters.AddWithValue("@matinhtrangsanpham", sanpham.Matinhtrangsanpham);
            cm.Parameters.AddWithValue("@tensanpham", sanpham.Tensanpham);
            cm.Parameters.AddWithValue("@chitiet", sanpham.Chitiet);
            cm.Parameters.AddWithValue("@giagoc", sanpham.Giagoc);
            cm.Parameters.AddWithValue("@tilegiam", sanpham.Tilegiam);
            cm.Parameters.AddWithValue("@giamgia", sanpham.Giamgia);
            cm.Parameters.AddWithValue("@phigiaohangtannoi", sanpham.Phigiaohangtannoi);
            cm.Parameters.AddWithValue("@ngaygiobatdau", sanpham.Ngaygiobatdau);
            cm.Parameters.AddWithValue("@ngaygioketthuc", sanpham.Ngaygioketthuc);
            cm.Parameters.AddWithValue("@luotquangcao", sanpham.Luotquangcao);
            cm.Parameters.AddWithValue("@dohapdan", sanpham.Dohapdan);
            cm.Parameters.AddWithValue("@hinhanh", sanpham.Hinhanh);
            cm.Parameters.AddWithValue("@slphieutoida", sanpham.Slphieutoida);
            cm.Parameters.AddWithValue("@slphieutoithieu", sanpham.Slphieutoithieu);
            cm.Parameters.AddWithValue("@hansudung", sanpham.Hansudung);
            cm.ExecuteNonQuery();
        }
        public void Update(tbsanpham sanpham)
        {
            SqlCommand cm = new SqlCommand("sanpham_Update", cn);
            cm.CommandType = CommandType.StoredProcedure;
            cm.Parameters.AddWithValue("@masanpham", sanpham.Madanhmuc);
            cm.Parameters.AddWithValue("@madanhmuc", sanpham.Madanhmuc);
            cm.Parameters.AddWithValue("@madiadiem", sanpham.Madiadiem);
            cm.Parameters.AddWithValue("@matinhtrangsanpham", sanpham.Matinhtrangsanpham);
            cm.Parameters.AddWithValue("@tensanpham", sanpham.Tensanpham);
            cm.Parameters.AddWithValue("@chitiet", sanpham.Chitiet);
            cm.Parameters.AddWithValue("@giagoc", sanpham.Giagoc);
            cm.Parameters.AddWithValue("@tilegiam", sanpham.Tilegiam);
            cm.Parameters.AddWithValue("@giamgia", sanpham.Giamgia);
            cm.Parameters.AddWithValue("@phigiaohangtannoi", sanpham.Phigiaohangtannoi);
            cm.Parameters.AddWithValue("@ngaygiobatdau", sanpham.Ngaygiobatdau);
            cm.Parameters.AddWithValue("@ngaygioketthuc", sanpham.Ngaygioketthuc);
            cm.Parameters.AddWithValue("@luotquangcao", sanpham.Luotquangcao);
            cm.Parameters.AddWithValue("@dohapdan", sanpham.Dohapdan);
            cm.Parameters.AddWithValue("@hinhanh", sanpham.Hinhanh);
            cm.Parameters.AddWithValue("@slphieutoida", sanpham.Slphieutoida);
            cm.Parameters.AddWithValue("@slphieutoithieu", sanpham.Slphieutoithieu);
            cm.Parameters.AddWithValue("@hansudung", sanpham.Hansudung);
            cm.ExecuteNonQuery();
        }
        public void Delete(int iD)
        {
            SqlCommand cm = new SqlCommand("sanpham_delete", cn);
            cm.CommandType = CommandType.StoredProcedure;
            cm.Parameters.AddWithValue("@masanpham", iD);
            cm.ExecuteNonQuery();
        }

        public tbsanphamcollection Get(string where, int pageindex, int pagesize, string orderby, string orderdirection, out int total)
        {
            throw new Exception("The method or operation is not implemented.");
        }
    }
}
